{% extends 'HrOnlineBundle::layout.html.twig' %}

{% block title %}{{ position.title }}{% endblock %}

{% block body %}

	<header>
			{% if  position.createdAt != null %}
				<div class="date"><time datetime="{{ position.createdAt|date('c') }}">{% trans %}Published{% endtrans %}: {{ position.createdAt|date('d.m.Y') }} | {{ position.createdAt| time_ago }}</time></div>
			{% endif %}
            <h2>{{ position.title }}</h2>
    </header>

	<div id="msgFromRemote"></div>

	{% include 'HrOnlineBundle:Default:_flashes.html.twig' %}
	
	{% if apply %}

		<section class="apply" id="apply">

			{% if app.user %}
			
				<input type="button" value="{% trans %}Apply for position{% endtrans %}" class="btn-apply" data-id="{{ position.id }}"  />		
			
			{% else %}
				
				<input type="button" value="{% trans %}Login and apply{% endtrans %}" class="btn-login-apply" data-id="{{ position.id }}"  />	

				<input type="button" value="{% trans %}Register and apply{% endtrans %}" class="btn-register-apply" data-id="{{ position.id }}"  />	

			{% endif %}
			</div>
			
			<div class="result"></div>

		</section>

	{% endif %}


    <article class="full gradient slightly-rounded">
		<p>
			{{ position.description | nl2br }}
		</p>
    </article>


	<div id="dialog" title="{% trans %}Login and apply{% endtrans %}" class="hidden">
		{{ include(
				'HrOnlineBundle:user:_loginForm.html.twig',
				{ 'position_id': position.id }
		)}}
	</div>


<script type="text/javascript">

$(function() {

    $( ".btn-login-apply" ).click( function() {
		
		var id = $( this ).data('id'); // position id

		$.get( "{{ path('hr_online_remember_position') }}",  { id: id },  function( response ) {

			$( "#msgFromRemote" ).html(response);

			$( "#dialog" ).dialog();

		});

		return false;
	});

    $( ".btn-register-apply" ).click( function() {
		
		var id = $( this ).data('id'); // position id

		$.post( "{{ path('hr_online_remember_position') }}",  { id: id },  function( response ) {

			window.location = "{{ path('hr_online_user_register') }}";

		});

		return false;
	});


    $( ".btn-apply" ).click( function() {
		
		var id = $( this ).data('id'); // position id

		$.post( "{{ path('hr_online_user_apply') }}",  { id: id },  function( response ) {

			$( ".flash" ).html(''); // clear previous messages

			$( "#apply" ).find( ".result" ).html( $.trim(response) );
			
			$( ".btn-apply" ).hide();

		});

		return false;
	});
});

</script>

{% endblock %}
